package net.lab1024.sa.admin.module.business.category.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.category.dao.FrontCategoryMapDao;
import net.lab1024.sa.admin.module.business.category.domain.entity.FrontCategoryMapEntity;
import net.lab1024.sa.admin.module.business.category.domain.form.FrontCategoryMapAddForm;
import net.lab1024.sa.admin.module.business.category.domain.form.FrontCategoryMapQueryForm;
import net.lab1024.sa.admin.module.business.category.domain.form.FrontCategoryMapUpdateForm;
import net.lab1024.sa.admin.module.business.category.domain.vo.FrontCategoryMapVO;
import net.lab1024.sa.common.common.util.SmartBeanUtil;
import net.lab1024.sa.common.common.util.SmartPageUtil;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.common.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 前台类目映射关系 Service
 *
 * @Author jabari
 * @Date 2023-06-01 15:12:35
 * @Copyright 51dev.cn
 */

@Service
public class FrontCategoryMapService {

    @Autowired
    private FrontCategoryMapDao frontCategoryMapDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<FrontCategoryMapVO> queryPage(FrontCategoryMapQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<FrontCategoryMapVO> list = frontCategoryMapDao.queryPage(page, queryForm);
        PageResult<FrontCategoryMapVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(FrontCategoryMapAddForm addForm) {
        FrontCategoryMapEntity frontCategoryMapEntity = SmartBeanUtil.copy(addForm, FrontCategoryMapEntity.class);
        frontCategoryMapDao.insert(frontCategoryMapEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(FrontCategoryMapUpdateForm updateForm) {
        FrontCategoryMapEntity frontCategoryMapEntity = SmartBeanUtil.copy(updateForm, FrontCategoryMapEntity.class);
        frontCategoryMapDao.updateById(frontCategoryMapEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        frontCategoryMapDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer mapId) {
        if (null == mapId){
            return ResponseDTO.ok();
        }

        frontCategoryMapDao.deleteById(mapId);
        return ResponseDTO.ok();
    }
}
